import os
import time

import pytest
from loguru import logger

from basic.base_assert import current_page
from basic.base_driver import DRIVER
from page.page_main import PageMain

MAIN = PageMain()

@pytest.fixture(scope='session', autouse=True)
def app():
    if DRIVER.is_app_installed("com.xiaomi.shop") is False:
        logger.info("未安装小米商城，开始安装")
        # DRIVER.install_app("app/xiaomi_shop.apk")
    yield
    logger.info("移除小米商城")
    # DRIVER.remove_app()


# 链路长，需要返回主页面
@pytest.fixture(scope='function', autouse=True)
def start_case():
    DRIVER.activate_app("com.xiaomi.shop")
    logger.info(f"{'=' *20}开始执行case{'=' *20}")
    yield
    logger.info(f"{'=' *20}执行case结束{'=' *20}")
    DRIVER.terminate_app("com.xiaomi.shop")

# 链路短，直接返回主页面
# @pytest.fixture(scope='function', autouse=True)
# def start_case():
#     logger.info(f"{'=' *20}开始执行case{'=' *20}")
#     while current_page() != "com.xiaomi.shop2.activity.MainActivity":
#         DRIVER.back()
#     yield
#     logger.info(f"{'=' *20}执行case结束{'=' *20}")
